package com.lysj.admin.master;

import com.lysj.admin.master.auth.domain.Role;
import com.lysj.admin.master.auth.service.RoleService;
import com.lysj.admin.master.common.CommonConstant;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Created by zk on 2019-12-05 5:15
 * @description
 */
@Component
public class InitApplicationRunner implements ApplicationRunner {
    @Resource
    private RoleService roleService;


    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        //生成管理员
        Role adminRole = roleService.getById(CommonConstant.ADMIN_ROLE_ID);
        if(adminRole == null){
            Role role = new Role();
            role.setName("管理员");
            role.setId(CommonConstant.ADMIN_ROLE_ID);
            roleService.save(role);
        }
    }
}
